package com.example.myspring.Listener;


import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;


//未完成
public class UserSessionListener implements HttpSessionListener,HttpSessionAttributeListener {

    public static int USER = 0;

    @Override//当属性被添加到会话时调用
    public void attributeAdded(HttpSessionBindingEvent event) {
        if((boolean) event.getSession().getAttribute("login")){
            USER++;
        }
        System.out.println("用户已创建");
        System.out.println("当前用户数量" + USER);
    }
    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        if(USER > 0){
            USER--;
            System.out.println("用户已销毁");
        }else{
            System.out.println("用户数为零，无法销毁");
        }
        System.out.println("当前用户数量" + USER);
    }
}
